/**
 * Created by ian0214 on 2017/7/19.
 */
function Controller() {
    var self = this;
    var editor = new Editor({
        containerId: "edit"
    });

    var preview = $("#preview");

    this.init = function () {
        var handler = function (e) {
            self.render(editor.getPureText());
        };

        $("#edit")//.on("DOMNodeInserted", handler)
            .on("keyup", handler)
            .on("paste", handler)
            .on("cut", handler);
    };

    this.render = function (rawMD) {
        var raw = '';
        if(arguments.length === 0){
            rawMD = editor.getPureText();
        }else{
            raw = rawMD;
        }
        var html = marked(raw);
        preview.html(html);
    }
}